/*
 * Station.cpp
 *
 *  Created on: 6 mars 2011
 *      Author: Julien
 */

#include "Station.h"
#include "Passager.h"

Station::Station(Section * section, bool term) {
	this->terminus=term;
	this->borneAchat = new BorneAchatTicket;
	this->attente = 0;
	this->insertion = 0;
	this->section = section; //Section où la station se situe
	this->fileAttente = new Passager*[30]; //Une station ne peut accueillir que trente voyageur
	cout << "*** Station créée ***" << endl;
}

bool Station::isTerminus(){
	return this->terminus;
}

void Station::afficher(){
	if (this->contientRame())
		cout << "|_T_|" << flush;
	else
		cout << "|_" << this->attente << "_|" << flush;
}

BorneAchatTicket* Station::getBorneAchat(){
	return this->borneAchat;
}

int Station::getNbAttente(){
	return this->attente;
}

int Station :: rejoindreFileAttente(Passager * p){
	this->fileAttente[insertion] = p;
	this->attente++;
	int tmp = insertion;
	insertion = (insertion + 1)%30; // Gestion circulaire des insertions dans la file.
	return tmp;
}

void Station::quitterFileAttente(int place){
	this->attente--;
	this->fileAttente[place] = NULL;
}

Passager ** Station::getFileAttente(){
	return this->fileAttente;
}

Station::~Station() {
	delete this->fileAttente;
}
